<?
if ($_POST[action] == "reg_contact")
{

	if (trim($_POST['myc_firstname']) == '')
	{
		$err .= "First name is required<br>";
	}
	if (trim($_POST['myc_lastname']) == '')
	{
		$err .= "Last Name is required<br>";
	}
	if (trim($_POST['myc_email']) == '')
	{
		$err .= "Contact Email  is required<br>";
	}elseif(!ereg("^[a-zA-Z0-9][a-zA-Z0-9_\.]+[a-zA-Z0-9]@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $_POST[myc_email])){
	      $err .= "Invalid Email address<br />";
	  
	}
	if ($err == '')
	{
		$myc_id		   = $_POST['editId'];
		$myc_rcid      = $_SESSION[uid];
		$myc_gid       = @implode(",",$_POST[myc_gid]);
		$myc_firstname		= htmlspecialchars(trim($_POST[myc_firstname]));
		$myc_lastname		= htmlspecialchars(trim($_POST[myc_lastname]));
		$myc_email			= htmlspecialchars(trim($_POST[myc_email]));
		$myc_jobtitle		= htmlspecialchars(trim($_POST[myc_jobtitle]));
		$myc_company		= htmlspecialchars(trim($_POST[myc_company]));
		$myc_address1       = htmlspecialchars(trim($_POST[myc_address1]));
		$myc_address2      = htmlspecialchars(trim($_POST[myc_address2]));
		$myc_city     = htmlspecialchars(trim($_POST[myc_city]));
		$myc_state   = htmlspecialchars(trim($_POST[myc_state]));
		$myc_zipcode   = htmlspecialchars(trim($_POST[myc_zipcode]));
		$myc_country   = htmlspecialchars(trim($_POST[myc_country]));
		$myc_mobilephone      = htmlspecialchars(trim($_POST[myc_mobilephone]));
		$myc_phone     = htmlspecialchars(trim($_POST[myc_phone]));
		$myc_fax  = htmlspecialchars(trim($_POST[myc_fax]));
		$myc_website   = htmlspecialchars(trim($_POST[myc_website]));
		$myc_industry   = htmlspecialchars(trim($_POST[myc_industry]));
		$myc_speciality1   = htmlspecialchars(trim($_POST[myc_speciality1]));
		$myc_speciality2    = htmlspecialchars(trim($_POST[myc_speciality2]));
		$myc_speciality3       = htmlspecialchars(trim($_POST[myc_speciality3]));
		$myc_notes      = htmlspecialchars(trim($_POST[myc_notes]));
		
		if($myc_id > 0){
			$sql = "UPDATE	`pa_mycontacts` SET 
				`myc_gid` = '".$myc_gid."',
				`myc_firstname` = '".$myc_firstname."',
				`myc_lastname` = '".$myc_lastname."',
				`myc_email` = '".$myc_email."',
				`myc_jobtitle` = '".$myc_jobtitle."',
				`myc_company` = '".$myc_company."',
				`myc_address1` = '".$myc_address1."',
				`myc_address2` = '".$myc_address2."',
				`myc_city` = '".$myc_city."',
				`myc_state` = '".$myc_state."',
				`myc_zipcode` = '".$myc_zipcode."',
				`myc_country` = '".$myc_country."',
				`myc_mobilephone` = '".$myc_mobilephone."',
				`myc_phone` = '".$myc_phone."',
				`myc_fax` = '".$myc_fax."',
				`myc_website` = '".$myc_website."',
				`myc_industry` = '".$myc_industry."',
				`myc_speciality1` = '".$myc_speciality1."',
				`myc_speciality2` = '".$myc_speciality2."',
				`myc_speciality3` = '".$myc_speciality3."',
				`myc_notes` = '".$myc_notes."'
				WHERE myc_rcid = '".$_SESSION[uid]."' AND myc_id = '".$myc_id."'
			";
			$DB->query($sql);
			$err  = "<h3 style=\"color:red\">Edited Successfully!</h3><meta http-equiv=\"refresh\" content=\"2;URL=postcontact.php?editId=$myc_id\">";
		
		}else{
			$sql = "INSERT INTO `pa_mycontacts` ( 
			`myc_rcid` , 
			`myc_gid` , 
			`myc_firstname` ,
			`myc_lastname` , 
			`myc_email` , 
			`myc_jobtitle` ,
			`myc_company`,
			`myc_address1`,
			`myc_address2` , 
			`myc_city` ,
			`myc_state` ,
			`myc_zipcode`,
			`myc_country` ,
			`myc_mobilephone` ,
			`myc_phone` ,
			`myc_fax` ,
			`myc_website`, 
			`myc_industry` ,
			`myc_speciality1`,
			`myc_speciality2` ,
			`myc_speciality3` ,
			`myc_notes` ,
			`myc_created` 
			) VALUES (
			'".$myc_rcid."', 
			'".$myc_gid."', 
			'".$myc_firstname."', 
			'".$myc_lastname."',
			'".$myc_email."',
			'".$myc_jobtitle."',
			'".$myc_company."',
			'".$myc_address1."', 
			'".$myc_address2."',
			'".$myc_city."',
			'".$myc_state."',
			'".$myc_zipcode."', 
			'".$myc_country."',
			'".$myc_mobilephone."', 
			'".$myc_phone."',
			'".$myc_fax."',
			'".$myc_website."', 
			'".$myc_industry."',
			'".$myc_speciality1."',
			'".$myc_speciality2."', 
			'".$myc_speciality3."', 
			'".$myc_notes."', '".time()."');";

			$DB->query($sql);
			$err  = "<h3 style=\"color:red\">Added Successfully!</h3><meta http-equiv=\"refresh\" content=\"2;URL=mycontacts.php\">";
		}	
	}
}
?>